package com.example.rentianjituan.myhuanxin;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.annotation.TargetApi;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.support.annotation.NonNull;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.app.LoaderManager.LoaderCallbacks;

import android.content.CursorLoader;
import android.content.Loader;
import android.database.Cursor;
import android.net.Uri;
import android.os.AsyncTask;

import android.os.Build;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.EditorInfo;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.easemob.EMCallBack;
import com.easemob.chat.EMChatManager;

import java.util.ArrayList;
import java.util.List;

import static android.Manifest.permission.READ_CONTACTS;

/**
 * A login screen that offers login via email/password.
 */
public class LoginActivity extends AppCompatActivity {

    private EditText etName;
    private EditText etPassword;
    private Button btLogin;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        etName= (EditText) findViewById(R.id.et_username);
        etPassword=(EditText) findViewById(R.id.et_password);
        btLogin= (Button) findViewById(R.id.bt_login);
        btLogin.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                EMChatManager.getInstance().login(etName.getText().toString(),
                        etPassword.getText().toString(), new EMCallBack() {
                            @Override
                            public void onSuccess() {
                                EMChatManager.getInstance().loadAllConversations();
                                startActivity(new Intent(LoginActivity.this,
                                        MainActivity.class));
                                finish();
                            }

                            @Override
                            public void onError(int i, String s) {
                                Toast.makeText(LoginActivity.this,"发送失败",Toast.LENGTH_SHORT).show();

                            }

                            @Override
                            public void onProgress(int i, String s) {
                                Toast.makeText(LoginActivity.this,"发送失败2",Toast.LENGTH_SHORT).show();

                            }
                        });
            }
        });
    }

}

